var proStr;
var proInfo;
var custStr;
var customer;
window.onload = function () {
    var date = new Date();
    //alert("012".slice(-2));
    var month = ("0" + (date.getMonth() + 1)).slice(-2);
    var day = ("0" + (date.getDate())).slice(-2);
    date = date.getFullYear()+"-" + month + "-" + day;
    $("#date").val(date);
    proStr = localStorage.getItem("proStr");
    if(proStr != null){
        proInfo = eval("("+ proStr +")");
        //alert(proStr);
        //console.log(proInfo);
        //显示图片
        $(".hairstyle_main .hairstyle_main_b .hairstyle_main_l").html("<img src=\"data:image/jpg;base64,"+ proInfo.productPhoto+"\" alt=\"\">");
        //显示商品信息
        $(".jishi_content2").html("<p class=\"t_primary14\" style=\"margin-top:4px;\">"+ proInfo.productName +"<span class=\"course_5\" style=\"position: absolute; bottom:15px; left:138px;\">￥"+ proInfo.rentPrice +"/天  &nbsp;押金:"+ proInfo.rentMoney +"元<span style=\"font-size: 13px;\"></span></span></p> \n" +
            "      \t\t\t\t\t <p style=\"margin-top: 10px;\"><span style=\"margin-right: 20px;\">颜色："+ proInfo.productColor +"</span></p> \n" +
            "      \t\t\t\t\t <p><span>数量： 1 个</span></p> \n") ;
        /*  "       \t\t\t\t\t<p style=\"width: 90%; overflow: hidden;text-overflow:ellipsis;white-space:nowrap;\">品牌："+ proInfo.productType +" </p> ");*/
        //显示租金
        $(".rent font").html(proInfo.rentMoney + "元");
        custStr = localStorage.getItem("customer");
        customer = eval("("+ custStr +")");
        if(customer != null){
            //封装客户信息
            $("#custName").val(customer.custName);
            $("#custPhone").val(customer.custPhone);
            $("#address").val(customer.consigeeAddr);
        }
    }
    else{
        alert("该商品可能已经报废,请返回主页!");
        window.location.href = "/index.html"
    }
};

function valiRentDays() {
    /*var date = $("#date").val();
    alert(date);
    console.log(date);*/
}

function addRentCart(){
   $(".btn2").attr("disabled","disabled");
    custStr = localStorage.getItem("customer");
    proStr = localStorage.getItem("proStr");
    var rentTime = $("#date").val();
    //console.log(custStr);
    //console.log(proStr);
    //if(rentDays)
    var rentDays = $("#rentDays").val();
    var data = "";
    if(custStr != null){
        data += "customer=" + custStr;

        if(proStr != null){
            data += "&product=" + proStr;
        }else{
            alert("该商品可能已经报废,请返回主页!");
            window.location.href = "/index.html"
        }
    }else{
        alert("用户登陆超时请重新登录!");
        window.location.href = "/login/login.html";
    }
    var url = "rentCart!addRentCart";
    data += "&rentDays=" + rentDays + "&rentTime=" + rentTime;
    //console.log(data);

    sendRequest("post",url,data,addRentCartBack);
}

function addRentCartBack(result) {
    //alert(result);
    //alert(result == "success");
    if(result == "\"success\""){
        alert("添加成功!");
        window.location.href = "rentCart.html";
    }else{
        alert("租物车加入失败,租物车里已含有该商品");
    }
}



